﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Entities;

namespace AbpToDomain.EntityInfo
{
    public class Box:Entity
    {
        [Key]
        public Guid Id_Box { get; set; }
        public string BoxCode {  get; set; }

        [Comment("格口数")]
        public int BoxGridQuantity { get; set; }    
        public DateTime CreateTime{ get; set; }
        public DateTime? UpdateTime { get; set;}
        [Comment("允许使用")]
        public bool IsEnable {  get; set; }
        [Comment("是否使用虚拟储位")]
        public bool VirtualSpace {  get; set; }
        public string? Info {  get; set; }
        public string? Remarks {  get; set; }
        [Comment("上下架频率")]
        public int Frequency {  get; set; }
        [Comment("机台")]
        public string? Machine{  get; set; }
        public override object[] GetKeys()
        {
           return new object[] { Id_Box };
        }
        public Box()
        {
            CreateTime = DateTime.Now;
            IsEnable = true;
        }
        //foreignkey
        public WarehouseLine? WarehouseLine { get; set; }
        public InlethouseLine? InlethouseLine { get; set; }
        public Guid? Id_WarehouseLine { get; set; }
        public Guid? Id_InlethouseLine { get; set; }
        public List<BoxGrid>? BoxGrids { get; set; } = new List<BoxGrid>();
        public TaskOrder? TaskOrder { get; set; }
        public BoxType? BinType { get; set; }
        //function
        public Box AddBox(string BoxCode, int BoxGridQuantity,bool virtualSpace,BoxType binType)
        {
            Box box = new Box();
            box.BoxCode = BoxCode;
            box.VirtualSpace = VirtualSpace;
            box.CreateTime = DateTime.Now;
            box.IsEnable = true;
            box.BoxGridQuantity = BoxGridQuantity;
            box.BinType = binType;
            return box;
        }
    }
    public class BoxGrid : Entity
    {
        [Key]
        public Guid Id_BoxGrid { get; set; }
        [Comment("格口序号")]
        public int Sequence {  get; set; }
        [Comment("格口号")]
        public string BoxGridCode {  get; set; }
        [Comment("储位数")]
        public int BoxPositionQuantity { get; set; }
        public override object[] GetKeys()
        {
            return new object[] { Id_BoxGrid };
        }
        //foreginkey
        public Box TheBox { get; set; }  
        public List<BoxPosition> BoxPositions { get; set; }=new List<BoxPosition>();
        //function
        public BoxGrid AddBoxGrid(int Sequence, string BoxGridCode,Box TheBox,int BoxPositionQuantity)
        {
            BoxGrid boxGrid = new BoxGrid();
            boxGrid.Sequence = Sequence;
            boxGrid.BoxGridCode = BoxGridCode;
            boxGrid.TheBox = TheBox;
            boxGrid.BoxPositionQuantity = BoxPositionQuantity;
            return boxGrid;
        }   
    }
    public class BoxPosition : Entity
    {
        [Key]
        public Guid Id_BoxPosition { get; set; }
        [Comment("储位号")]
        public string BoxPositionCode { get; set; }
        public DateTime? UpdateTime { get; set; }
        [Comment("位次")]
        public int SeatoOrder { get; set; }
        //foreginkey
        public BoxGrid TheBoxGrid { get; set; }
        public MaterialBase? MaterialBase { get; set; }
        public override object[] GetKeys()
        {
            return new object[] { Id_BoxPosition };
        }
        //function
        public BoxPosition AddBoxPosition(string BoxPositionCode, BoxGrid boxGrid,int seateorder)
        {
            BoxPosition boxPosition = new BoxPosition();
            boxPosition.BoxPositionCode = BoxPositionCode;
            boxPosition.TheBoxGrid = boxGrid;
            boxPosition.SeatoOrder = seateorder;
            return boxPosition;
        }
    }
}
